<?php require_once("include/conexion.php"); ?>
<?php require_once("cotiza/lib/Quick_CSV_import.php"); ?>
<?php
	$user = $_POST['user'];
	$pass = md5($_POST['pass']);
	
	mysql_select_db($database_cotiza, $cotiza);
	$query = "SELECT * FROM usuarios WHERE usuario = '$user' AND passwd = '$pass'";
	$cotiza = mysql_query($query, $cotiza) or die(mysql_error());
	$row = mysql_fetch_assoc($cotiza);
	$totalRows = mysql_num_rows($cotiza);

	if($totalRows == 1)
	{
		session_start();
		if($row['activo'] == 1)
		{
			$_SESSION['usuario']     = $row['usuario'];
			$_SESSION['nombre']      = $row['nombre'];
			$_SESSION['permisos']    = $row['permisos'];
			$_SESSION['autenticado'] = 1;
			
			//shell_exec("/u1/users/pfs/cotizador/load_cmmstr.sh");
			$csv = new Quick_CSV_import("c:\\cm_mstr.csv");
			$csv->table_name = "cm_mstr";
			//$csv->field_enclose_char = "'";
			$csv->import();
			
			header("Location: main.php");
		}
		else
			header("Location: index.php?err=2");
	}
	else
		header("Location: index.php?err=1");
?>